package com.lry.jvm.instructions.constants;


import com.lry.jvm.instructions.base.Index16Instruction;
import com.lry.jvm.instructions.base.NoOperandsInstruction;
import com.lry.jvm.rtda.Frame;
import com.lry.jvm.rtda.OperandStack;
import com.lry.jvm.rtda.heap.RuntimeConstantPool;
import com.lry.jvm.util.Util;
//Push long or double from run-time constant pool (wide index)
public class ldc2_w extends Index16Instruction {

    @Override
    public byte getOpCode() {
        return 0x14;
    }

    @Override
    public String getReName() {
        return "ldc2_w";
    }

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();
        RuntimeConstantPool rcp = frame.getMethod().getJClass().getConstantPool();

        Object obj = rcp.getConstant(index);

        if(obj instanceof Long){
            stack.pushLong((Long) obj);
        }else if(obj instanceof Double){
            stack.pushDouble((Double) obj);
        }else{
            Util.panic("java.lang.ClassFormatError");
        }
    }
}
